package me.riverslob.test.esper.http;

import com.espertech.esper.client.Configuration;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esperio.http.EsperIOHTTPAdapter;
import com.espertech.esperio.http.config.ConfigurationHTTPAdapter;
import com.espertech.esperio.http.config.Request;

/**
 * <br/>Created on 13-9-12 上午9:42
 *
 * @author 郑治明（zm.zheng@zhuche.com）
 * @since 3.1.11
 */
public class OutPutSampleMain {
    private final static String ENGINE_URI = "TestHTTPAdapterOutput";

    public static void main(String[] args) {
        ConfigurationHTTPAdapter adapterConfig = new ConfigurationHTTPAdapter();

        Request requestOne = new Request();
        requestOne.setStream("SupportBean");
        requestOne.setUri("http://localhost:8082/root");
        adapterConfig.getRequests().add(requestOne);

        /*Request requestTwo = new Request();
        requestTwo.setStream("SupportBean");
        requestTwo.setUri("http://localhost:8077/root/${stream}/${stringProp}/${intProp}");
        adapterConfig.getRequests().add(requestTwo);
*/
        EsperIOHTTPAdapter adapter = new EsperIOHTTPAdapter(adapterConfig, ENGINE_URI);

        Configuration engineConfig = new Configuration();
        engineConfig.addEventType("SupportBean", SupportBean.class);
        engineConfig.addEventType("SupportBeanTwo", SupportBeanTwo.class);
        EPServiceProvider provider = EPServiceProviderManager.getProvider(ENGINE_URI, engineConfig);

        adapter.start();

//        EPStatement stmt = provider.getEPAdministrator().createEPL("insert into SupportBean select id as stringProp, 5 as intProp from SupportBeanTwo");
//        stmt.addListener(listener);


        provider.getEPRuntime().sendEvent(new SupportBean("intProp",5));
        provider.getEPRuntime().sendEvent(new SupportBeanTwo("intProp-id"));

        adapter.destroy();
        provider.destroy();

    }
}
